How to Create ZUGFeRD / Factur-X PDF Invoices with DocuGenerate

Blog image
Author By DocuGenerate

March 08, 2025

What is Electronic Invoicing?

Electronic invoicing (e-invoicing) is the exchange of invoice documents between suppliers and buyers in a structured electronic format. Unlike traditional paper invoices or simple PDF files sent via email, e-invoices contain structured data that can be automatically processed by accounting systems, reducing manual data entry and improving accuracy.

The European Union has been driving the adoption of e-invoicing through various directives and standards. In Germany, e-invoicing becomes mandatory for B2B transactions starting January 1, 2025, while France will require it by September 2026. These regulations are designed to improve efficiency, reduce costs, and enhance tax compliance across the European market.

E-invoices typically come in different formats, but one of the most popular approaches is the hybrid format that combines both human-readable and machine-readable elements in a single document. This approach ensures compatibility with existing workflows while enabling automated processing. E-invoice generation can be integrated into various business workflows:

  • ERP Integration: Trigger e-invoice generation when invoices are approved in your ERP system
  • E-commerce Platforms: Automatically generate e-invoices for online orders
  • Subscription Systems: Create recurring e-invoices for subscription-based services
  • Project Management: Generate e-invoices based on completed project milestones

Understanding Hybrid E-Invoice Formats

Hybrid e-invoice formats represent the best of both worlds: they maintain the familiar PDF presentation that humans can read and understand, while embedding structured XML data that machines can process automatically. The most prominent examples of this approach are ZUGFeRD (developed in Germany) and Factur-X (developed in France), which have been harmonized and are now essentially the same standard.

Key Components of Hybrid E-Invoices

A hybrid e-invoice consists of several essential components:

  • PDF/A-3 Document: The visual representation of the invoice that looks like a traditional invoice. PDF/A-3 is specifically chosen because it supports embedded file attachments while maintaining long-term archival capabilities.

  • Embedded XML File: Machine-readable structured data that contains all invoice information in a standardized format. This XML follows international standards like UN/CEFACT Cross Industry Invoice (CII).

  • Metadata: Special metadata embedded in the PDF that identifies the document as an e-invoice and provides information about the embedded XML structure.

  • Digital Signatures: Optional cryptographic signatures that ensure document integrity and authenticity.

Standards and Naming Conventions

Different e-invoicing standards require specific naming conventions for the embedded XML files:

  • ZUGFeRD 1.0: The XML file must be named ZUGFeRD-invoice.xml
  • ZUGFeRD 2.0: The XML file must be named zugferd-invoice.xml
  • ZUGFeRD 2.1 and Factur-X: The XML file must be named factur-x.xml
  • Italian FatturaPA: Must match the invoice ID, e.g., IT01234567890_00001.xml

For most European implementations, following the Factur-X standard with the filename factur-x.xml provides the broadest compatibility.

The DocuGenerate Approach to E-Invoicing

DocuGenerate provides a practical solution for generating e-invoices by focusing on the PDF generation aspect while supporting XML attachments through its API. This approach recognizes that while the PDF can be dynamically generated from templates, the XML structure often requires specialized validation and compliance checking that is best handled by dedicated systems.

Two-Step Process

Creating compliant e-invoices with DocuGenerate involves a two-step process:

1. Generate the XML Structure: Use specialized e-invoicing libraries or services to create compliant XML data that follows the required standards (ZUGFeRD, Factur-X, etc.).

2. Generate the PDF with Embedded XML: Use DocuGenerate to create the PDF invoice while attaching the pre-generated XML file.

This separation of concerns ensures that both components meet their respective requirements: the XML maintains strict compliance with e-invoicing standards, while the PDF provides professional presentation and branding flexibility.

XML Generation Considerations

The XML component of an e-invoice must be carefully crafted to ensure compliance with the chosen standard. Key considerations include:

  • Data Accuracy: All values in the XML must exactly match those displayed in the PDF.
  • Validation: The XML should be validated against the appropriate XSD schema and Schematron rules.
  • Profile Selection: Choose the appropriate profile (Minimum, Basic, EN16931, Extended) based on your requirements.
  • Code Lists: Use the correct code lists for countries, currencies, tax categories, and other standardized values.

Implementing E-Invoice Generation

Let’s walk through a practical implementation of e-invoice generation using DocuGenerate’s API with PDF attachments.

Step 1: Prepare Your Invoice Template

Create a professional invoice template in Microsoft Word or another supported format. The template should include merge tags for all the dynamic content that will be populated from your data source. As shown in the template below, you’ll need to strategically place merge tags throughout the document to capture all necessary invoice information.

Word template of the invoice

The invoice template featured in this tutorial includes the following merge tags:

Customer Information:

  • [Company Name] - The customer’s company name
  • [Street Address] - Customer’s street address
  • [City] - Customer’s city
  • [State] - Customer’s state or region
  • [Zip Code] - Customer’s postal code

Invoice Details:

  • [Invoice No] - Unique invoice identifier
  • [Invoice Date] - Date the invoice was issued

Line Items (using list syntax):

  • [#Items]...[/] - Loop structure for multiple invoice line items
  • [Description] - Product or service description
  • [Quantity] - Number of items
  • [Price] - Unit price per item
  • [Amount] - Total amount for the line item

Totals:

  • [Sub Total] - Sum of all line items before tax
  • [Tax Rate] - Tax percentage rate
  • [Tax Total] - Total tax amount
  • [Total] - Final invoice total including tax

Step 2: Prepare Your Invoice Data

Before generating the invoice, you need to prepare your data in JSON format. The JSON keys must exactly match the merge tags in your template for proper substitution. Each key corresponds to a merge tag in the template - for example, the JSON key "Company Name" will replace the [Company Name] merge tag in the document.

Here’s the sample JSON data that corresponds to our invoice template:

[
  {
    "Company Name": "TechGear Solutions",
    "Invoice No": "INV-2025-001",
    "Street Address": "82 Bashford Avenue",
    "City": "Chicago",
    "State": "IL",
    "Zip Code": "60652",
    "Invoice Date": "March 8, 2025",
    "Items": [
      {
        "Description": "Wireless Mouse",
        "Quantity": "5",
        "Price": "$29.99",
        "Amount": "$149.95"
      },
      {
        "Description": "USB-C Cable (2m)",
        "Quantity": "10",
        "Price": "$12.50",
        "Amount": "$125.00"
      },
      {
        "Description": "Laptop Stand",
        "Quantity": "3",
        "Price": "$45.00",
        "Amount": "$135.00"
      }
    ],
    "Sub Total": "$409.95",
    "Tax Rate": "20",
    "Tax Total": "$81.99",
    "Total": "$491.94"
  }
]

Notice how the Items array contains multiple objects, each representing a line item on the invoice. This structure works with the [#Items]...[/] loop syntax in the template to generate multiple rows in the invoice table.

Step 3: Generate Compliant XML

Before creating the PDF, you need to generate the XML structure that will be embedded in the PDF. All values in the XML file must match the corresponding values in your JSON dataset that populates the PDF, such as invoice numbers, amounts, dates, line items, and totals. Any discrepancies between the PDF and XML data can cause validation failures or processing issues with recipient systems.

Here’s a simplified example of what a Factur-X XML structure might look like:

<?xml version="1.0" encoding="UTF-8"?>
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
                          xmlns:a="urn:un:unece:uncefact:data:standard:QualifiedDataType:100"
                          xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:10"
                          xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
                          xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <rsm:ExchangedDocumentContext>
        <ram:GuidelineSpecifiedDocumentContextParameter>
            <ram:ID>urn:cen.eu:en16931:2017</ram:ID>
        </ram:GuidelineSpecifiedDocumentContextParameter>
    </rsm:ExchangedDocumentContext>
    <rsm:ExchangedDocument>
        <ram:ID>INV-2025-001</ram:ID>
        <ram:TypeCode>380</ram:TypeCode>
        <ram:IssueDateTime>
            <udt:DateTimeString format="102">20250308</udt:DateTimeString>
        </ram:IssueDateTime>
    </rsm:ExchangedDocument>
    <rsm:SupplyChainTradeTransaction>
        <ram:IncludedSupplyChainTradeLineItem>
            <ram:AssociatedDocumentLineDocument>
                <ram:LineID>1</ram:LineID>
            </ram:AssociatedDocumentLineDocument>
            <ram:SpecifiedTradeProduct>
                <ram:Name>Wireless Mouse</ram:Name>
            </ram:SpecifiedTradeProduct>
            <ram:SpecifiedLineTradeAgreement>
                <ram:NetPriceProductTradePrice>
                    <ram:ChargeAmount>29.99</ram:ChargeAmount>
                </ram:NetPriceProductTradePrice>
            </ram:SpecifiedLineTradeAgreement>
            <ram:SpecifiedLineTradeDelivery>
                <ram:BilledQuantity unitCode="C62">5.0000</ram:BilledQuantity>
            </ram:SpecifiedLineTradeDelivery>
            <ram:SpecifiedLineTradeSettlement>
                <ram:ApplicableTradeTax>
                    <ram:TypeCode>VAT</ram:TypeCode>
                    <ram:CategoryCode>S</ram:CategoryCode>
                    <ram:RateApplicablePercent>20</ram:RateApplicablePercent>
                </ram:ApplicableTradeTax>
                <ram:SpecifiedTradeSettlementLineMonetarySummation>
                    <ram:LineTotalAmount>149.95</ram:LineTotalAmount>
                </ram:SpecifiedTradeSettlementLineMonetarySummation>
            </ram:SpecifiedLineTradeSettlement>
        </ram:IncludedSupplyChainTradeLineItem>
        <ram:IncludedSupplyChainTradeLineItem>
            <ram:AssociatedDocumentLineDocument>
                <ram:LineID>2</ram:LineID>
            </ram:AssociatedDocumentLineDocument>
            <ram:SpecifiedTradeProduct>
                <ram:Name>USB-C Cable (2m)</ram:Name>
            </ram:SpecifiedTradeProduct>
            <ram:SpecifiedLineTradeAgreement>
                <ram:NetPriceProductTradePrice>
                    <ram:ChargeAmount>12.50</ram:ChargeAmount>
                </ram:NetPriceProductTradePrice>
            </ram:SpecifiedLineTradeAgreement>
            <ram:SpecifiedLineTradeDelivery>
                <ram:BilledQuantity unitCode="C62">10.0000</ram:BilledQuantity>
            </ram:SpecifiedLineTradeDelivery>
            <ram:SpecifiedLineTradeSettlement>
                <ram:ApplicableTradeTax>
                    <ram:TypeCode>VAT</ram:TypeCode>
                    <ram:CategoryCode>S</ram:CategoryCode>
                    <ram:RateApplicablePercent>20</ram:RateApplicablePercent>
                </ram:ApplicableTradeTax>
                <ram:SpecifiedTradeSettlementLineMonetarySummation>
                    <ram:LineTotalAmount>125.00</ram:LineTotalAmount>
                </ram:SpecifiedTradeSettlementLineMonetarySummation>
            </ram:SpecifiedLineTradeSettlement>
        </ram:IncludedSupplyChainTradeLineItem>
        <ram:IncludedSupplyChainTradeLineItem>
            <ram:AssociatedDocumentLineDocument>
                <ram:LineID>3</ram:LineID>
            </ram:AssociatedDocumentLineDocument>
            <ram:SpecifiedTradeProduct>
                <ram:Name>Laptop Stand</ram:Name>
            </ram:SpecifiedTradeProduct>
            <ram:SpecifiedLineTradeAgreement>
                <ram:NetPriceProductTradePrice>
                    <ram:ChargeAmount>45.00</ram:ChargeAmount>
                </ram:NetPriceProductTradePrice>
            </ram:SpecifiedLineTradeAgreement>
            <ram:SpecifiedLineTradeDelivery>
                <ram:BilledQuantity unitCode="C62">3.0000</ram:BilledQuantity>
            </ram:SpecifiedLineTradeDelivery>
            <ram:SpecifiedLineTradeSettlement>
                <ram:ApplicableTradeTax>
                    <ram:TypeCode>VAT</ram:TypeCode>
                    <ram:CategoryCode>S</ram:CategoryCode>
                    <ram:RateApplicablePercent>20</ram:RateApplicablePercent>
                </ram:ApplicableTradeTax>
                <ram:SpecifiedTradeSettlementLineMonetarySummation>
                    <ram:LineTotalAmount>135.00</ram:LineTotalAmount>
                </ram:SpecifiedTradeSettlementLineMonetarySummation>
            </ram:SpecifiedLineTradeSettlement>
        </ram:IncludedSupplyChainTradeLineItem>
        <ram:ApplicableHeaderTradeAgreement>
            <ram:SellerTradeParty>
                <ram:Name>DocuGenerate</ram:Name>
                <ram:PostalTradeAddress>
                    <ram:PostcodeCode>90013</ram:PostcodeCode>
                    <ram:LineOne>93 East Lassen Street</ram:LineOne>
                    <ram:CityName>Los Angeles</ram:CityName>
                    <ram:CountryID>US</ram:CountryID>
                </ram:PostalTradeAddress>
                <ram:SpecifiedTaxRegistration>
                    <ram:ID schemeID="VA">US12367623</ram:ID>
                </ram:SpecifiedTaxRegistration>
            </ram:SellerTradeParty>
            <ram:BuyerTradeParty>
                <ram:Name>TechGear Solutions</ram:Name>
                <ram:PostalTradeAddress>
                    <ram:PostcodeCode>60652</ram:PostcodeCode>
                    <ram:LineOne>82 Bashford Avenue</ram:LineOne>
                    <ram:CityName>Chicago</ram:CityName>
                    <ram:CountryID>US</ram:CountryID>
                </ram:PostalTradeAddress>
            </ram:BuyerTradeParty>
        </ram:ApplicableHeaderTradeAgreement>
        <ram:ApplicableHeaderTradeDelivery>
            <ram:ActualDeliverySupplyChainEvent>
                <ram:OccurrenceDateTime>
                    <udt:DateTimeString format="102">20250308</udt:DateTimeString>
                </ram:OccurrenceDateTime>
            </ram:ActualDeliverySupplyChainEvent>
        </ram:ApplicableHeaderTradeDelivery>
        <ram:ApplicableHeaderTradeSettlement>
            <ram:InvoiceCurrencyCode>USD</ram:InvoiceCurrencyCode>
            <ram:ApplicableTradeTax>
                <ram:CalculatedAmount>81.99</ram:CalculatedAmount>
                <ram:TypeCode>VAT</ram:TypeCode>
                <ram:BasisAmount>409.95</ram:BasisAmount>
                <ram:CategoryCode>S</ram:CategoryCode>
                <ram:RateApplicablePercent>20</ram:RateApplicablePercent>
            </ram:ApplicableTradeTax>
            <ram:SpecifiedTradePaymentTerms>
                <ram:DueDateDateTime>
                    <udt:DateTimeString format="102">20250308</udt:DateTimeString>
                </ram:DueDateDateTime>
            </ram:SpecifiedTradePaymentTerms>
            <ram:SpecifiedTradeSettlementHeaderMonetarySummation>
                <ram:LineTotalAmount>409.95</ram:LineTotalAmount>
                <ram:TaxBasisTotalAmount>409.95</ram:TaxBasisTotalAmount>
                <ram:TaxTotalAmount currencyID="USD">81.99</ram:TaxTotalAmount>
                <ram:GrandTotalAmount>491.94</ram:GrandTotalAmount>
                <ram:DuePayableAmount>491.94</ram:DuePayableAmount>
            </ram:SpecifiedTradeSettlementHeaderMonetarySummation>
        </ram:ApplicableHeaderTradeSettlement>
    </rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>

You can enhance both your template and XML with additional business information such as:

  • Payment Information: IBAN account details, ACH routing numbers, payment terms
  • Contact Details: Contact persons for both buyer and seller parties
  • Reference Numbers: Purchase order numbers, delivery note references, contract numbers
  • Additional Addresses: Delivery addresses, billing addresses different from company address
  • Tax Details: Multiple tax rates, tax exemptions, reverse charge indicators

Step 4: Create the PDF with Embedded XML

Once you have your XML file ready, you can attach it to the PDF using DocuGenerate’s PDF attachments feature. The API supports two methods for providing the XML file:

  1. Direct URL: If your XML file is hosted online, you can provide the direct URL
  2. Base64 data URI: For local files or when you want to embed the content directly

For the Base64 approach, the data URI format should be data:text/xml;name=factur-x.xml;base64,{BASE64_ENCODED_XML} and you can use various online tools or command-line utilities to convert your XML file to Base64. For the sample XML shown above, you can use the pre-encoded Base64 XML file that corresponds to our example data.

Here’s how to use DocuGenerate’s API to generate the PDF invoice with the XML attached:

curl -X 'POST' \
  'https://api.docugenerate.com/v1/document' \
  -H 'accept: application/json' \
  -H 'Authorization: 491c000c5fad32ed7787005b0723ad55' \
  -H 'Content-Type: application/json' \
  -d '{
  "template_id": "7VYocxLnIupLU3YT4iLr",
  "data": [{
    "Company Name": "TechGear Solutions",
    "Invoice No": "INV-2025-001",
    "Street Address": "82 Bashford Avenue",
    "City": "Chicago",
    "State": "IL",
    "Zip Code": "60652",
    "Invoice Date": "March 8, 2025",
    "Items": [
      {
        "Description": "Wireless Mouse",
        "Quantity": "5",
        "Price": "$29.99",
        "Amount": "$149.95"
      },
      {
        "Description": "USB-C Cable (2m)",
        "Quantity": "10",
        "Price": "$12.50",
        "Amount": "$125.00"
      },
      {
        "Description": "Laptop Stand",
        "Quantity": "3",
        "Price": "$45.00",
        "Amount": "$135.00"
      }
    ],
    "Sub Total": "$409.95",
    "Tax Rate": "20",
    "Tax Total": "$81.99",
    "Total": "$491.94"
  }],
  "output_format": ".pdf/a-3b",
  "attach": "data:text/xml;name=factur-x.xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJzbTpDcm9zc0luZHVzdHJ5SW52b2ljZSB4bWxuczpyc209InVybjp1bjp1bmVjZTp1bmNlZmFjdDpkYXRhOnN0YW5kYXJkOkNyb3NzSW5kdXN0cnlJbnZvaWNlOjEwMCIKICAgICAgICAgICAgICAgICAgICAgICAgICB4bWxuczphPSJ1cm46dW46dW5lY2U6dW5jZWZhY3Q6ZGF0YTpzdGFuZGFyZDpRdWFsaWZpZWREYXRhVHlwZToxMDAiCiAgICAgICAgICAgICAgICAgICAgICAgICAgeG1sbnM6cWR0PSJ1cm46dW46dW5lY2U6dW5jZWZhY3Q6ZGF0YTpzdGFuZGFyZDpRdWFsaWZpZWREYXRhVHlwZToxMCIKICAgICAgICAgICAgICAgICAgICAgICAgICB4bWxuczpyYW09InVybjp1bjp1bmVjZTp1bmNlZmFjdDpkYXRhOnN0YW5kYXJkOlJldXNhYmxlQWdncmVnYXRlQnVzaW5lc3NJbmZvcm1hdGlvbkVudGl0eToxMDAiCiAgICAgICAgICAgICAgICAgICAgICAgICAgeG1sbnM6dWR0P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QZXJjZW50PjIwPC9yYW06UmF0ZUFwcGxpY2FibGVQZXJjZW50PgogICAgICAgICAgICAgICAgPC9yYW06QXBwbGljYWJsZVRyYWRlVGF4PgogICAgICAgICAgICAgICAgPHJhbTpTcGVjaWZpZWRUcmFkZVNldHRsZW1lbnRMaW5lTW9uZXRhcnlTdW1tYXRpb24+CiAgICAgICAgICAgICAgICAgICAgPHJhbTpMaW5lVG90YWxBbW91bnQ+MTQ5Ljk1PC9yYW06TGluZVRvdGFsQW1vdW50PgogICAgICAgICAgICAgICAgPC9yYW06U3BlY2lmaWVkVHJhZGVTZXR0bGVtZW50TGluZU1vbmV0YXJ5U3VtbWF0aW9uPgogICAgICAgICAgICA8L3JhbTpTcGVjaWZpZWRMaW5lVHJhZGVTZXR0bGVtZW50PgogICAgICAgIDwvcmFtOkluY2x1ZGVkU3VwcGx5Q2hhaW5UcmFkZUxpbmVJdGVtPgogICAgICAgIDxyYW06SW5jbHVkZWRTdXBwbHlDaGFpblRyYWRlTGluZUl0ZW0+CiAgICAgICAgICAgIDxyYW06QXNzb2NpYXRlZERvY3VtZW50TGluZURvY3VtZW50PgogICAgICAgICAgICAgICAgPHJhbTpMaW5lSUQ+MjwvcmFtOkxpbmVJRD4KICAgICAgICAgICAgPC9yYW06QXNzb2NpYXRlZERvY3VtZW50TGluZURvY3VtZW50PgogICAgICAgICAgICA8cmFtOlNwZWNpZmllZFRyYWRlUHJvZHVjdD4KICAgICAgICAgICAgICAgIDxyYW06TmFtZT5VU0ItQyBDYWJsZSAoMm0pPC9yYW06TmFtZT4KICAgICAgICAgICAgPC9yYW06U3BlY2lmaWVkVHJhZGVQcm9kdWN0PgogICAgICAgICAgICA8cmFtOlNwZWNpZmllZExpbmVUcmFkZUFncmVlbWVudD4KICAgICAgICAgICAgICAgIDxyYW06TmV0UHJpY2VQcm9kdWN0VHJhZGVQcmljZT4KICAgICAgICAgICAgICAgICAgICA8cmFtOkNoYXJnZUFtb3VudD4xMi41MDwvcmFtOkNoYXJnZUFtb3VudD4KICAgICAgICAgICAgICAgIDwvcmFtOk5ldFByaWNlUHJvZHVjdFRyYWRlUHJpY2U+CiAgICAgICAgICAgIDwvcmFtOlNwZWNpZmllZExpbmVUcmFkZUFncmVlbWVudD4KICAgICAgICAgICAgPHJhbTpTcGVjaWZpZWRMaW5lVHJhZGVEZWxpdmVyeT4KICAgICAgICAgICAgICAgIDxyYW06QmlsbGVkUXVhbnRpdHkgdW5pdENvZGU9IkM2MiI+MTAuMDAwMDwvcmFtOkJpbGxlZFF1YW50aXR5PgogICAgICAgICAgICA8L3JhbTpTcGVjaWZpZWRMaW5lVHJhZGVEZWxpdmVyeT4KICAgICAgICAgICAgPHJhbTpTcGVjaWZpZWRMaW5lVHJhZGVTZXR0bGVtZW50PgogICAgICAgICAgICAgICAgPHJhbTpBcHBsaWNhYmxlVHJhZGVUYXg+CiAgICAgICAgICAgICAgICAgICAgPHJhbTpUeXBlQ29kZT5WQVQ8L3JhbTpUeXBlQ29kZT4KICAgICAgICAgICAgICAgICAgICA8cmFtOkNhdGVnb3J5Q29kZT5TPC9yYW06Q2F0ZWdvcnlDb2RlPgogICAgICAgICAgICAgICAgICAgIDxyYW06UmF0ZUFwcGxpY2FibGVQZXJjZW50PjIwPC9yYW06UmF0ZUFwcGxpY2FibGVQZXJjZW50PgogICAgICAgICAgICAgICAgPC9yYW06QXBwbGljYWJsZVRyYWRlVGF4PgogICAgICAgICAgICAgICAgPHJhbTpTcGVjaWZpZWRUcmFkZVNldHRsZW1lbnRMaW5lTW9uZXRhcnlTdW1tYXRpb24+CiAgICAgICAgICAgICAgICAgICAgPHJhbTpMaW5lVG90YWxBbW91bnQ+MTI1LjAwPC9yYW06TGluZVRvdGFsQW1vdW50PgogICAgICAgICAgICAgICAgPC9yYW06U3BlY2lmaWVkVHJhZGVTZXR0bGVtZW50TGluZU1vbmV0YXJ5U3VtbWF0aW9uPgogICAgICAgICAgICA8L3JhbTpTcGVjaWZpZWRMaW5lVHJhZGVTZXR0bGVtZW50PgogICAgICAgIDwvcmFtOkluY2x1ZGVkU3VwcGx5Q2hhaW5UcmFkZUxpbmVJdGVtPgogICAgICAgIDxyYW06SW5jbHVkZWRTdXBwbHlDaGFpblRyYWRlTGluZUl0ZW0+CiAgICAgICAgICAgIDxyYW06QXNzb2NpYXRlZERvY3VtZW50TGluZURvY3VtZW50PgogICAgICAgICAgICAgICAgPHJhbTpMaW5lSUQ+MzwvcmFtOkxpbmVJRD4KICAgICAgICAgICAgPC9yYW06QXNzb2NpYXRlZERvY3VtZW50TGluZURvY3VtZW50PgogICAgICAgICAgICA8cmFtOlNwZWNpZmllZFRyYWRlUHJvZHVjdD4KICAgICAgICAgICAgICAgIDxyYW06TmFtZT5MYXB0b3AgU3RhbmQ8L3JhbTpOYW1lPgogICAgICAgICAgICA8L3JhbTpTcGVjaWZpZWRUcmFkZVByb2R1Y3Q+CiAgICAgICAgICAgIDxyYW06U3BlY2lmaWVkTGluZVRyYWRlQWdyZWVtZW50PgogICAgICAgICAgICAgICAgPHJhbTpOZXRQcmljZVByb2R1Y3RUcmFkZVByaWNlPgogICAgICAgICAgICAgICAgICAgIDxyYW06Q2hhcmdlQW1vdW50PjQ1LjAwPC9yYW06Q2hhcmdlQW1vdW50PgogICAgICAgICAgICAgICAgPC9yYW06TmV0UHJpY2VQcm9kdWN0VHJhZGVQcmljZT4KICAgICAgICAgICAgPC9yYW06U3BlY2lmaWVkTGluZVRyYWRlQWdyZWVtZW50PgogICAgICAgICAgICA8cmFtOlNwZWNpZmllZExpbmVUcmFkZURlbGl2ZXJ5PgogICAgICAgICAgICAgICAgPHJhbTpCaWxsZWRRdWFudGl0eSB1bml0Q29kZT0iQzYyIj4zLjAwMDA8L3JhbTpCaWxsZWRRdWFudGl0eT4KICAgICAgICAgICAgPC9yYW06U3BlY2lmaWVkTGluZVRyYWRlRGVsaXZlcnk+CiAgICAgICAgICAgIDxyYW06U3BlY2lmaWVkTGluZVRyYWRlU2V0dGxlbWVudD4KICAgICAgICAgICAgICAgIDxyYW06QXBwbGljYWJsZVRyYWRlVGF4PgogICAgICAgICAgICAgICAgICAgIDxyYW06VHlwZUNvZGU+VkFUPC9yYW06VHlwZUNvZGU+CiAgICAgICAgICAgICAgICAgICAgPHJhbTpDYXRlZ29yeUNvZGU+UzwvcmFtOkNhdGVnb3J5Q29kZT4KICAgICAgICAgICAgICAgICAgICA8cmFtOlJhdGVBcHBsaWNhYmxlUGVyY2VudD4yMDwvcmFtOlJhdGVBcHBsaWNhYmxlUGVyY2VudD4KICAgICAgICAgICAgICAgIDwvcmFtOkFwcGxpY2FibGVUcmFkZVRheD4KICAgICAgICAgICAgICAgIDxyYW06U3BlY2lmaWVkVHJhZGVTZXR0bGVtZW50TGluZU1vbmV0YXJ5U3VtbWF0aW9uPgogICAgICAgICAgICAgICAgICAgIDxyYW06TGluZVRvdGFsQW1vdW50PjEzNS4wMDwvcmFtOkxpbmVUb3RhbEFtb3VudD4KICAgICAgICAgICAgICAgIDwvcmFtOlNwZWNpZmllZFRyYWRlU2V0dGxlbWVudExpbmVNb25ldGFyeVN1bW1hdGlvbj4KICAgICAgICAgICAgPC9yYW06U3BlY2lmaWVkTGluZVRyYWRlU2V0dGxlbWVudD4KICAgICAgICA8L3JhbTpJbmNsdWRlZFN1cHBseUNoYWluVHJhZGVMaW5lSXRlbT4KICAgICAgICA8cmFtOkFwcGxpY2FibGVIZWFkZXJUcmFkZUFncmVlbWVudD4KICAgICAgICAgICAgPHJhbTpTZWxsZXJUcmFkZVBhcnR5PgogICAgICAgICAgICAgICAgPHJhbTpOYW1lPkRvY3VHZW5lcmF0ZTwvcmFtOk5hbWU+CiAgICAgICAgICAgICAgICA8cmFtOlBvc3RhbFRyYWRlQWRkcmVzcz4KICAgICAgICAgICAgICAgICAgICA8cmFtOlBvc3Rjb2RlQ29kZT45MDAxMzwvcmFtOlBvc3Rjb2RlQ29kZT4KICAgICAgICAgICAgICAgICAgICA8cmFtOkxpbmVPbmU+OTMgRWFzdCBMYXNzZW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iAgICA8L3JzbTpTdXBwbHlDaGFpblRyYWRlVHJhbnNhY3Rpb24+CjwvcnNtOkNyb3NzSW5kdXN0cnlJbnZvaWNlPg=="
}'

The name=factur-x.xml value is an important part of the attach parameter as it specifies the attachment filename to match the Factur-X naming scheme required by the standard. Additionally, using the .pdf/a-3b output format is necessary for creating a PDF/A-3 compliant document, which is required for e-invoicing standards as it supports embedded file attachments while maintaining long-term archival capabilities.

Step 5: Validate the Result

After generation, the resulting PDF contains a professional invoice matching your template, along with the embedded XML file. You can verify the attachment by opening the PDF in a viewer that supports attachments, such as Adobe Acrobat Reader, where you’ll see the factur-x.xml file listed in the Attachments panel.

Generated PDF with XML attachment visible

Best Practices for E-Invoice Implementation

Data Consistency

Maintaining perfect synchronization between your PDF presentation and embedded XML data is one of the most critical aspects of e-invoice implementation. Since recipients may use either the visual PDF or the structured XML for processing, any inconsistencies can lead to payment delays, compliance issues, or outright rejection by automated systems.

Ensure that all amounts, dates, and other critical information are identical between the PDF and the embedded XML. Pay special attention to calculations, tax amounts, and totals, as these are often the first elements validated by recipient systems. Any discrepancies can cause validation failures or processing issues.

Error Handling

Robust error handling is essential for maintaining system reliability and ensuring smooth operations when processing high volumes of invoices. E-invoicing systems face unique challenges because they must coordinate between multiple components (XML generation, PDF creation, and attachment processes) while maintaining strict compliance requirements. Implement comprehensive error handling for both XML generation and PDF creation, with proper logging and recovery mechanisms. Common issues include:

  • Invalid XML structure or missing required fields
  • Calculation errors between PDF and XML amounts
  • Incorrect file naming or attachment parameters
  • Template rendering errors

Testing and Validation

Thorough testing is crucial for e-invoicing systems because compliance failures can result in legal issues, payment delays, and damaged business relationships. Unlike traditional document generation, e-invoices must pass multiple validation layers including technical XML validation, business rule checking, and regulatory compliance verification. Before deploying your e-invoicing system, establish a comprehensive testing strategy that covers both technical and business scenarios:

  • Validate XML files against official XSD schemas and Schematron rules
  • Test with various invoice scenarios (different currencies, tax rates, line items)
  • Verify PDF/A-3b compliance using validation tools
  • Test with recipient systems to ensure proper processing

Future-Proofing Your E-Invoice System

Standards Evolution

E-invoicing standards continue to evolve rapidly as governments and international organizations refine their requirements. Regular updates to code lists and validation rules occur bi-annually in many jurisdictions, while new profile requirements and optional features are introduced to support industry needs and cross-border interoperability. Digital signature and security enhancements are also being developed to address cybersecurity threats and ensure document authenticity.

Regulatory Changes

Governments worldwide are implementing e-invoicing mandates at different paces, with Germany’s B2B requirement starting in 2025 and France following in 2026. Changes to tax reporting requirements often accompany these mandates, requiring real-time transmission of invoice data to tax authorities. New compliance and archival obligations are being introduced, while cross-border trade facilitation measures require systems to support multiple standards simultaneously.

Technology Improvements

Emerging technologies are reshaping the e-invoicing landscape with new automation, security, and efficiency opportunities. Blockchain-based verification systems provide immutable audit trails, while AI-powered data extraction tools improve processing accuracy and reduce manual intervention. Real-time tax calculation capabilities enable automatic compliance across multiple jurisdictions, and enhanced mobile solutions offer more flexible invoicing options. Designing systems with extensibility in mind allows easier incorporation of these advances as they mature.

Conclusion

Building a robust e-invoicing system with DocuGenerate provides a practical path to compliance with European and global e-invoicing requirements. By separating XML creation from PDF generation, you can ensure both technical compliance and presentation flexibility. This hybrid approach of combining structured XML data with professional PDF presentation offers the best user experience while meeting regulatory requirements.

Whether you’re implementing e-invoicing for a small business or a large enterprise, the principles and patterns outlined in this guide provide a solid foundation for success. As e-invoicing becomes mandatory across more markets, having a scalable and compliant system in place will provide significant competitive advantages. Remember to stay current with evolving standards, validate your implementations thoroughly, and design for scalability from the beginning.

Resources

Share This Post